home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F42586_testBuildListWhileMap.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-02-06  |  4.4 KB  |  121 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:xalan="http://xml.apache.org/xalan"
  3. xmlns:myHalve="myHalve" 
  4. xmlns:myTenXController="myTenXController" 
  5. xmlns:myEasyDiffMap="myEasyDiffMap"
  6. xmlns:myWithinController="myWithinController" 
  7. xmlns:myFunction="myFunction" 
  8. exclude-result-prefixes="xsl xalan myHalve myTenXController
  9.  myEasyDiffMap myFunction myWithinController"
  10. >
  11.   <xsl:import href="buildListWhileMap.xsl"/>
  12.  
  13.   <!-- To be applied on any xml. This produces the derivative of
  14.        x^2 for x = 6, with precision 0.00001
  15.    -->
  16.    
  17.   <xsl:output indent="yes" omit-xml-declaration="yes"/>
  18.   
  19.   <myHalve:myHalve/>
  20.   <myWithinController:myWithinController/>
  21.   <myTenXController:myTenXController/>
  22.   <myEasyDiffMap:myEasyDiffMap/>
  23.   <myFunction:myFunction/>
  24.   
  25.   <xsl:variable name="vMyHalveGenerator" select="document('')/*/myHalve:*[1]"/>
  26.   <xsl:variable name="vmyWithinController" select="document('')/*/myWithinController:*[1]"/>
  27.   <xsl:variable name="vmyEasyDiffMap" select="document('')/*/myEasyDiffMap:*[1]"/>
  28.   <xsl:variable name="vmyFunction" select="document('')/*/myFunction:*[1]"/>
  29.   
  30.   <xsl:template match="/">
  31.     <xsl:variable name="fx">
  32.       <xsl:apply-templates select="$vmyFunction">
  33.         <xsl:with-param name="pParam" select="6"/>
  34.       </xsl:apply-templates>
  35.     </xsl:variable>
  36.     
  37.     <xsl:variable name="vrtfMapParams">
  38.      <xsl:copy-of select="$vmyFunction"/>
  39.      <param>6</param>
  40.      <param><xsl:value-of select="$fx"/></param>
  41.     </xsl:variable>
  42.     
  43.     <xsl:variable name="vMapParams" select="xalan:nodeset($vrtfMapParams)/*"/>
  44.     
  45.     <xsl:call-template name="buildListWhileMap">
  46.         <xsl:with-param name="pGenerator" select="$vMyHalveGenerator"/>
  47.         <xsl:with-param name="pParam0" select="0.1"/>
  48.         <xsl:with-param name="pController" select="$vmyWithinController"/>
  49.         <xsl:with-param name="pContollerParam" select="0.00001"/>
  50.         <xsl:with-param name="pMap" select="$vmyEasyDiffMap"/>
  51.         <xsl:with-param name="pMapParams" select="$vMapParams"/>
  52.     </xsl:call-template>
  53.   </xsl:template>
  54.   
  55.   <xsl:template name="myHalveGenerator" match="*[namespace-uri()='myHalve']">
  56.      <xsl:param name="pParams" select="/.."/>
  57.      <xsl:param name="pList" select="/.."/>
  58.      
  59.      <xsl:choose>
  60.        <xsl:when test="not($pList)"><xsl:value-of select="$pParams"/></xsl:when>
  61.        <xsl:otherwise><xsl:value-of select="$pList[last()] div 2"/></xsl:otherwise>
  62.      </xsl:choose>
  63.   </xsl:template>
  64.  
  65.   <xsl:template name="myWithinController" match="*[namespace-uri()='myWithinController']">
  66.      <xsl:param name="pParams" select="/.."/>
  67.      <xsl:param name="pList" select="/.."/>
  68.      
  69.      <xsl:variable name="vLastDiff" select="$pList[last()] - $pList[last() - 1]"/>
  70.      
  71.      
  72.      <xsl:choose>
  73.        <xsl:when test="not($vLastDiff < $pParams 
  74.                       and $vLastDiff > (0 - $pParams))
  75.                       ">1</xsl:when>
  76.      </xsl:choose>
  77.   </xsl:template>
  78.  
  79.   <xsl:template name="myEasyDiffMap" match="*[namespace-uri()='myEasyDiffMap']">
  80.      <xsl:param name="pParams" select="/.."/>
  81.      <xsl:param name="pDynParams" select="/.."/>
  82.      <xsl:param name="pList" select="/.."/>
  83.      
  84.      <xsl:variable name="x" select="$pParams[2]"/>
  85.      <xsl:variable name="h" select="$pDynParams[1]"/>
  86.      
  87.      
  88.      <xsl:choose>
  89.          <xsl:when test="not($h = 0)">
  90.              <xsl:variable name="fx_plus_h">
  91.                  <xsl:apply-templates select="$pParams[1]">
  92.                    <xsl:with-param name="pParam" select="$x + $h"/>
  93.                  </xsl:apply-templates>
  94.              </xsl:variable>
  95.              
  96.              <xsl:variable name="fx">
  97.                  <xsl:choose>
  98.                      <xsl:when test="count($pParams) >= 3">
  99.                        <xsl:value-of select="$pParams[3]"/>
  100.                      </xsl:when>
  101.                      <xsl:otherwise>
  102.                          <xsl:apply-templates select="$pParams[1]">
  103.                            <xsl:with-param name="pParam" select="$x"/>
  104.                          </xsl:apply-templates>
  105.                      </xsl:otherwise>
  106.                  </xsl:choose>
  107.              </xsl:variable>
  108.              
  109.              <xsl:value-of select="($fx_plus_h - $fx) div $h"/>
  110.          </xsl:when>
  111.          <xsl:otherwise><xsl:value-of select="$pList[last()]"/></xsl:otherwise>
  112.      </xsl:choose>
  113.   </xsl:template>
  114.  
  115.   <xsl:template name="myFunction" match="*[namespace-uri()='myFunction']">
  116.      <xsl:param name="pParam" select="/.."/>
  117.      
  118.      <xsl:value-of select="$pParam * $pParam"/>
  119.   </xsl:template>
  120.  
  121. </xsl:stylesheet>